﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DCTLib.Common
{
    public class AppCookieInfo
    {
        private static int GetInt(string key)
        {
            string ID = CookieHelper.GetCookie(key);

            if (string.IsNullOrEmpty(ID))
                return -1;

            try
            {
                return Convert.ToInt32(ID);
            }
            catch
            {
                return -1;
            }
        }

        public static int AdminID
        {
            set
            {
                CookieHelper.SetCookie(AppCookieKeys.ADMINID, value.ToString());
            }
            get
            {
                return GetInt(AppCookieKeys.ADMINID);
            }
        }

        public static int UserID
        {
            set
            {
                CookieHelper.SetCookie(AppCookieKeys.USERID, value.ToString());
            }
            get
            {
                return GetInt(AppCookieKeys.USERID);
            }
        }

        /// <summary>
        /// AppCookieKeys declare enum in AppSettingKeys.cs
        /// </summary>
        public static string HashedPassword
        {
            set
            {
                string fakePassword = RandomGenerator.GetRandomString(5) + value + RandomGenerator.GetRandomString(3);
                CookieHelper.SetCookie(AppCookieKeys.HASHED_PASSWORD, fakePassword);
            }
            get
            {
                string fakePassword = CookieHelper.GetCookie(AppCookieKeys.HASHED_PASSWORD);
                if (string.IsNullOrEmpty(fakePassword))
                {
                    return string.Empty;
                }
                else
                {
                    return fakePassword.Substring(5, fakePassword.Length - 8);
                }
            }
        }


    }
}
